home *** CD-ROM | disk | FTP | other *** search
/ Garbo / Garbo.cdr / mac / source / tifreadr.sit / Tiff Window DEMO / Open Color Window.c < prev    next >
Text File  |  1990-04-21  |  5KB  |  122 lines

  1.  #include "my color.h"
  2. PixMapHandle    read_tiff_file(CWindowPtr);
  3. void    dispose_of_TIFF(CWindowPtr);    /* Dispose of all the CGrafPtr variables!! */
  4.  
  5. OpenWindow()    /* Open a new window */
  6. {
  7. Rect    resize_rect;
  8. CGrafPtr    the_tiff_picture;    /* to receive the off screen PixMap containing the TIFF picture */
  9. char    wNameDef[256];            /* to hold our default window title */
  10. char    nextWTitle[256];        /* title of next window to be opened*/
  11. char    *wName;
  12. ControlHandle    control;        /* I'll adjust all the scroll bars to accommodate the size of the TIFF picture */                 
  13. PaletteHandle    WindowPalette;
  14.  
  15.     NumToString (nextWNum, nextWTitle);          /* prepare number for title -- returns C string */
  16.     PtoCstr(nextWTitle);                    /* convert to 'C' type string    */
  17.     strcpy((char *)wNameDef,WindName);        /* WindName is a #define */
  18.     wName = (char *)strcat((char *)wNameDef,(char *)nextWTitle);
  19.     CtoPstr(wNameDef);                        /* convert to 'PASCAL' type string    */
  20.  
  21.     myWindow = (CWindowPtr)NewCWindow (nil, &nextWRect, wNameDef, true, documentProc,
  22.             (CWindowPtr)-1, true, 0);
  23.     WindowPalette = GetNewPalette(0);
  24.     SetPalette(myWindow, WindowPalette, TRUE);
  25.  
  26.  
  27.     SetPort (myWindow);                /*make it the current port*/
  28.  
  29.     add_scroll_bars(myWindow);    /* create some scroll bars for the new window */
  30.     set_color(myWindow);            /* set the window's color to something hideous */
  31.  
  32.  
  33.     OffsetRect (&nextWRect, windDX, windDY);/*move window down and right*/
  34.     if (nextWRect.right > dragRect.right)        /*move back if it's too far over*/
  35.         OffsetRect (&nextWRect, -nextWRect.left + leftEdge, 0);
  36.     if (nextWRect.bottom > dragRect.bottom)
  37.         OffsetRect (&nextWRect, 0, -nextWRect.top + topEdge);
  38.     nextWNum++;        /*bump number for next window*/
  39.  
  40.     the_tiff_picture = (CGrafPtr)read_tiff_file(myWindow); /* Now read the TIFF file for this window */
  41.  
  42.     if(the_tiff_picture)    /* If we successfully read a TIFF file, then resize the window to accommodate the image */
  43.     {
  44.         resize_rect = (**(*the_tiff_picture).portPixMap).bounds;
  45.         if((resize_rect.right + BAR_WIDTH) > screenBits.bounds.right) 
  46.             resize_rect.right = screenBits.bounds.right - (4 * BAR_WIDTH);
  47.         if((resize_rect.bottom + BAR_WIDTH) > screenBits.bounds.bottom) 
  48.             resize_rect.bottom = screenBits.bounds.bottom - (4 * BAR_WIDTH);
  49.         SizeWindow(myWindow, resize_rect.right + BAR_WIDTH, 
  50.             resize_rect.bottom + BAR_WIDTH, TRUE);        /* resize the window to hold the TIFF picture */
  51.         adjust_scroll_bars(myWindow);
  52.         control = ((CWindowPeek)myWindow)->controlList;
  53.         while(control)        /* set the control's maximum value to be the size of the TIFF rect */
  54.         {
  55.             if(GetCRefCon(control) == (long)VERTICLE_SCROLL)
  56.                 SetCtlMax(control, (**(*the_tiff_picture).portPixMap).bounds.bottom);
  57.             else if(GetCRefCon(control) == (long)HORIZONTAL_SCROLL)
  58.                 SetCtlMax(control, (**(*the_tiff_picture).portPixMap).bounds.right);
  59.     
  60.             control = (*control)->nextControl;
  61.         }
  62.         (*the_tiff_picture).portRect = resize_rect;
  63.         SetWRefCon(myWindow, the_tiff_picture);    /* make the window point to the off screen Pix map containing the TIFF picture */
  64.     }
  65.     else
  66.     SetWRefCon(myWindow, 0L);    /*We could not open the TIFF picture, make the window as containing no TIFF pictures */
  67.     menusOK = false;
  68.     EnableItem (myMenus [editM],0); /*in case this is the only window*/
  69. }  /* OpenWindow */
  70.  
  71.  
  72. KillWindow(theWindow)    /*Close a window and throw everything away*/
  73.  
  74. CWindowPtr        theWindow;
  75.  
  76. {
  77. CWindowPtr    front_window;
  78. extern    Boolean    file_in_use;
  79.  
  80.     front_window = (CWindowPtr)FrontWindow();
  81.     dispose_of_TIFF(front_window);
  82.  
  83.     DisposeWindow (theWindow);
  84.                     /*    throw away WindowRecord    */
  85.     front_window = (CWindowPtr)FrontWindow();
  86.     if (front_window == nil)                    /*if no more windows, disable Close*/
  87.         {        
  88.             DisableItem (myMenus[fileM], closeItem);
  89.             SetCursor(&arrow);
  90.         }
  91.     else /* FrontWindow() != nil */
  92.     {
  93.       if (((CWindowPeek)front_window)->windowKind < 0)
  94.             /*if a desk acc is coming up, enable undo*/
  95.         {
  96.             EnableItem (myMenus[editM], undoItem);
  97.             SetCursor(&arrow);
  98.         }
  99.        else 
  100.             DisableItem (myMenus[editM], undoItem);
  101.     } /* else */
  102. } /*KillWindow*/
  103.         
  104. void    dispose_of_TIFF(front_window)    /* Dispose of all the CGrafPtr variables!! */
  105. CWindowPtr    front_window;
  106. {
  107. PaletteHandle    picture_palette;
  108. CGrafPtr        the_picture;
  109.  
  110.  
  111.     the_picture = (CGrafPtr)((CWindowPeek)front_window)->refCon;
  112.     if(the_picture)
  113.     {
  114.         picture_palette = GetPalette(front_window);
  115.         DisposePalette(front_window);
  116.         DisposHandle((**(*the_picture).portPixMap).pmTable);
  117.         DisposPtr((**(*the_picture).portPixMap).baseAddr);
  118.         DisposHandle((*the_picture).portPixMap);
  119.         DisposPtr(the_picture);
  120.     }
  121.     return;
  122. }